import re

import requests


# 方式一 （简单，弹幕少）
url = 'https://api.bilibili.com/x/v1/dm/list.so?oid=1361326389'
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
reponses = requests.get(url=url,headers=headers)
reponses.encoding = reponses.apparent_encoding
#方式一，根据标签匹配
#lists =  re.findall('<d p=".*?">(.*?)</d>',reponses.text)
#方式二：根据正则匹配，只匹配中文
lists = re.findall('[\u4e00-\u9fa5]+',reponses.text)
content = '\n'.join(lists)
with open('方式一弹幕.txt',mode='a',encoding='utf-8') as f:
    f.write(content)
